package com.kai;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 通过url取得文件返回InputStream类型数据
 */
public class HttpUtils {
 
	/**
	 * 通过图片url返回图片Bitmap
	 * @param path  图片的url路径
	 * @return
	 */
	public static InputStream returnBitMap(String path) {
		URL url = null;
		InputStream is =null;
		try {
			url = new URL(path);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		try {
			//利用HttpURLConnection对象,我们可以从网络中获取网页数据.
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setDoInput(true);
			conn.connect();
			//得到网络返回的输入流
			is = conn.getInputStream();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return is;
	}
}